home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / database / postgres / appgen-0.2-a / appgen-0 / AppGEN / src / lib / encoding.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-10  |  1.4 KB  |  80 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <unistd.h>
  5.  
  6.  
  7. char *ag_parse(char *output,char *arg, int type)
  8. {
  9.     char *input,variable[256],value[256],blank[256];
  10.     char num[6];
  11.     int a=0,b=0,c;
  12.     for (a=0; a<256; a++) {
  13.         value[a]=0;
  14.         blank[a]=0;
  15.         }
  16.     a=0;
  17.     input=getenv("QUERY_STRING");
  18.     while (b<strlen(input)) {
  19.         strcpy(variable,"");
  20.         while ((input[b]!='=') && (b<strlen(input))) {
  21.             variable[a]=input[b];
  22.             a++;
  23.             b++;
  24.             }
  25.         variable[a]=0;
  26.         a=0;
  27.         b++;
  28.         if (type!=1) {
  29.             strcpy(value,"'");
  30.             a=1;
  31.             }
  32.         while ((input[b]!='&') && (b<strlen(input))) {
  33.             if (input[b]=='+') value[a]=' ';
  34.             else if (input[b]=='%') {
  35.                 c=0;
  36.                 b++;
  37.                 while((c<6)&&(input[b]>='0')&&(input[b]<='F')) {
  38.                     num[c]=input[b];
  39.                     c++;
  40.                     b++;
  41.                     }
  42.                 num[c]=0;
  43.                 value[a]=(char) strtol(num,(char **)NULL,16);
  44.                 b--;
  45.                 }
  46.             else value[a]=input[b];
  47.             if (value[a]=='\'') value[a]='`';
  48.             a++;
  49.             b++;
  50.             }
  51.         if (type!=1) {
  52.             value[a]='\'';
  53.             value[a+1]=0;
  54.             }
  55.         else value[a]=0;
  56.         a=0;
  57.         b++;
  58.         if (strcmp(arg,variable)==0) {
  59.             if (strlen(value)==0) strcpy(output,blank);
  60.             else strcpy(output,value);
  61.             return(output);
  62.             }
  63.         }
  64.     strcpy(output,blank);
  65.     return(output);
  66. }
  67.  
  68. char *ag_encode(char* output, char *inp1)
  69. {
  70.     char input[256];
  71.     int a;
  72.     strcpy(input,inp1);
  73.     for (a=0; a<strlen(input); a++) {
  74.         if (input[a]==' ') output[a]='+';
  75.         else output[a]=input[a];
  76.         }
  77.     output[a]=0;
  78.     return(output);
  79. }
  80.